package cn.bonoon.kernel;

/**
 * 通过核心框架自动生成的类，都统一的使用内核的<code>KernelClassLoader</code>进行加载
 * @author jackson
 *
 */
public class KernelClassLoader extends ClassLoader{
	private final static KernelClassLoader KERNEL_CLASS_LOADER = new KernelClassLoader();
	private final ClassLoader parent;
	private KernelClassLoader() {
		parent = getClass().getClassLoader();
	}
	
	public static Class<?> register(String className, byte[] classData){
		 return KERNEL_CLASS_LOADER.defineClass(className, classData, 0, classData.length, null);
	}
	
	public static ClassLoader getClassLoader(){
		return KERNEL_CLASS_LOADER;
	}
	
	@Override
	protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
		try{
			return parent.loadClass(name);
		}catch(ClassNotFoundException ex){
			return super.loadClass(name, resolve);
		}
	}
	
}
